package com.hqyj.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.system.pojo.SysUser;
import com.hqyj.system.dao.SysUserMapper;
import com.hqyj.system.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.utile.MdFive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author rock
 * @since 2021-11-30
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public HashMap<String, Object> select(SysUser sysUser) {
        return (HashMap<String, Object>) sysUserMapper.selectList(sysUser);
    }

    @Override
    public List<SysUser> queryList(Integer currentPage, Integer size, String search) {
        return sysUserMapper.queryList((currentPage-1)*size,size,search);
    }

    @Override
    public Boolean login(String username, String password) {
        HashMap<String, Object> map = new HashMap<>();
        MdFive mdFive = new MdFive();
        map.put("username", username);
        map.put("password",mdFive.encrypt(password,username));
        System.out.println(mdFive.encrypt(password,username));
        List<SysUser> sysUsers = sysUserMapper.selectByMap(map);
        return sysUsers!=null&&sysUsers.size()==1;
    }
}
